package com.cndw.kungfu.dao;

import java.util.List;

import com.cndw.dao.jade.Identity;
import com.cndw.dao.jade.annotation.DAO;
import com.cndw.dao.jade.annotation.SQL;
import com.cndw.dao.jade.annotation.SQLParam;
import com.cndw.kungfu.domain.LotteryLog;
import com.cndw.kungfu.domain.LotteryMode;

@DAO
public interface LotteryDao {
	public static final String tableLottey = "kfsys_lottery";
	public static final String tableLog = "kf_lottery_log";
	public static final String fieldsLog = "id,type,playerId,playerName,donType,donNum,maxLevel,awards,addTime,gold";

	@SQL("select id,type,level,rate,m,goodsId,rateIds,num,hidden,levelMin,levelMax from " + tableLottey + " order by type asc,id asc")
	public List<LotteryMode> getLotterys();

	@SQL("INSERT INTO " + tableLog + " (" + fieldsLog + ") VALUES(0,:type,:playerId,:playerName,:donType,:donNum,:maxLevel,:awards,:addTime,:gold)")
	public Identity insert(@SQLParam("type") int type, @SQLParam("playerId") long playerId, @SQLParam("playerName") String playerName,
			@SQLParam("donType") int donType, @SQLParam("donNum") int donNum, @SQLParam("maxLevel") int maxLevel, @SQLParam("awards") String awards,
			@SQLParam("addTime") int addTime,@SQLParam("gold") int gold);

	@SQL("Select " + fieldsLog + " from " + tableLog
			+ " where 1 #if(:type>0){ and type=:type} #else {and type in (1,2,3)}  #if(:playerId>0){ and playerId=:playerId} #if(:minLevel>0){ and maxLevel=:minLevel} order by id desc limit :limit ")
	public List<LotteryLog> selectLogs(@SQLParam("type") int type, @SQLParam("playerId") long playerId, @SQLParam("limit") int limit,
			@SQLParam("minLevel") int minLevel);

	@SQL(" select sum(gold) from " + tableLog + " where playerId=:1 #if(:2>0){ and type=:2} and addTime>=:3 and addTime <= :4 ")
	public int setTotal(long playerId, int type, int beginTime, int endTime);
	
}
